package com.zdsoft.blp.zongbuju.shouye.bianmin.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.API.API;
import com.zdsoft.blp.gongyong.application.MyApp;
import com.zdsoft.blp.gongyong.imageFrame.IvFrameView;
import com.zdsoft.blp.gongyong.net.BaseActivity;
import com.zdsoft.blp.gongyong.net.Net;
import com.zdsoft.blp.gongyong.net.NetCallback;
import com.zdsoft.blp.zongbuju.shouye.bianmin.entity.SheQu;
import com.zdsoft.blp.zongbuju.shouye.bianmin.entity.ZhiNan;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/1.
 */
public class BMxqActivity extends BaseActivity implements NetCallback{
    private TextView tv_xq_title,tv_xq_time,tv_xq_content;
    private TextView tv_title;
    private IvFrameView iv;
    private List<String>list;
    private LinearLayout ll_bk;
    @Override
    protected void init(){
        setContentView(R.layout.bianmin_xq);
        tv_title = find(R.id.tv_title);
        tv_title.setText("详情");
        ll_bk=find(R.id.ll_bk);
        tv_xq_title=find(R.id.tv_xq_title);
        tv_xq_time=find(R.id.tv_xq_time);
        tv_xq_content=find(R.id.tv_xq_content);
        iv=find(R.id.iv);

        Intent intent = getIntent();
        String id=intent.getStringExtra("id");

        Net net=new Net();
        net.url= API.GENERALINFO_URL;
        net.nameSpace=API.GENERALINFO_NAMESPACE;
        net.methodName=API.GENERALIFOCONTENT ;
        Map<String,Object> map=new HashMap<>();
        map.put("id",id);
        net.parms=map;
        getServer(net,this);
    }


    @Override
    public void onResponse(boolean flag, int code, String res) {
        Log.e("res",res);
        list=new ArrayList<>();
        String picture="";
        try {
            JSONObject object=new JSONObject(res);
            String content=object.getString("content");
            String title=object.getString("title");
            String releaseDate=object.getString("releaseDate");
            tv_xq_title.setText(title);
            tv_xq_content.setText(Html.fromHtml(content));
            tv_xq_time.setText(releaseDate);
            JSONArray array=object.getJSONArray("picPathSet");
            for(int j=0;j<array.length();j++){
                JSONObject object2=array.getJSONObject(j);
                picture=object2.getString("picPath");
                list.add(picture);
            }

            if (!picture.equals("")){
                ll_bk.setVisibility(View.VISIBLE);
                iv.setVisibility(View.VISIBLE);
                iv.show(list);
            }else {
                ll_bk.setVisibility(View.GONE);
                iv.setVisibility(View.GONE);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
